import 'package:flutter/material.dart';

import 'alert/alert.dart';

class BackConfirmation extends StatelessWidget {
  final Widget child;
  final String backConfirmationText;

  const BackConfirmation({
    @required this.backConfirmationText,
    @required this.child,
  });

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: child,
      onWillPop: () async {
        return showAlert<bool>(
          context,
          content: backConfirmationText,
          onConfirm: (context) {
            Navigator.pop(context, true);
          },
          onCancel: (context) {
            Navigator.pop(context, false);
          },
        );
      },
    );
  }
}
